package com.van.stockanalysis.service;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.van.stockanalysis.dao.UserDao;
import com.van.stockanalysis.pojo.User;

public class ModifyUserInformationService {
	public static boolean modify(String username,String password,String nickname,
			String email,String delete){
		String source = "mybatis-config.xml";
		InputStream inputstream = ModifyUserInformationService.class.getClassLoader().getResourceAsStream(source);
		SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession session = factory.openSession(); 
		UserDao userdao = session.getMapper(UserDao.class);
		
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		user.setNickname(nickname);
		user.setEmail(email);
		
		
		if(delete == "true"){
			boolean success = userdao.delete(user);
			return success;
		}
		boolean update = userdao.update(user);
		return update;
	}
}
